package com.itheima.controller;

import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public List<User> findAll() {
        List<User> userList = userService.findAll();
        System.out.println("findAll");
        return userList;
    }

    @RequestMapping("/findById")
    public User findById(int id) {
        User user = userService.findById(id);
        System.out.println(user);
        System.out.println("findById");
        return user;
    }

    @RequestMapping("/update")
    public void update(@RequestBody User user) {
        userService.update(user);
        System.out.println("update");
    }
}
